package com.example.demo.Controller;

import com.example.demo.Entity.transfer.UserDTO;
import com.example.demo.Service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;



@RestController
@RequestMapping("/user")
@Api("控制器接口")
public class UserController {

	@Autowired
	private UserService userService;


	//根据手机号获取指定用户信息
	@ApiOperation(value="获取指定用户信息",notes="根据手机号")
	@ApiParam("参数手机号,实例：http:localhost:8088/user/15071255833")
	@GetMapping(value="/{phone}")
	public Map<String, Object> QueryUserInfoByIdMedicalcare(@PathVariable(value = "phone") String phone){
		return userService.getUserInfoByPhone(phone);
	}




	//登陆接口
	//0：用户，1：医生
	@GetMapping(value="/1/{phone}")
	public Map<String, Object> login(@PathVariable("phone") String phone, @RequestParam("password") String password, HttpServletRequest request, HttpServletResponse response) {
		System.err.println("哈哈");
		response.addHeader("Access-Control-Allow-Origin", "*");

		int role = 1;
		return userService.QueryUserLogin(phone,password,role);
	}


	//注册接口
	/**
	 * @paramrole:1：医生
	 */
	@PostMapping()
	public Map<String, Object> registers( HttpServletRequest request, HttpServletResponse response) {
		response.addHeader("Access-Control-Allow-Origin", "*");
		int role = 1;
		UserDTO userDTO = new UserDTO();
		userDTO.setPhone(request.getParameter("phone"));
		userDTO.setPassWord(request.getParameter("password"));
		userDTO.setRealName(request.getParameter("name"));
		userDTO.setSex(request.getParameter("sex"));
		userDTO.setPosition(request.getParameter("position"));
		userDTO.setDepartment(request.getParameter("department"));
		userDTO.setRole(role);
		return userService.Userregisters(userDTO);
	}









}
